package ro.theneckmaster.usbSync;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Folder {

	private String path;
	private String relativePath;
	private List<MyFile> files = new ArrayList<MyFile>();
	private List<Folder> subFolders = new ArrayList<Folder>();
	
	private int subFolderNr = 0;
	private int filesNr = 0;
	private long totalSize = 0;
	
	private boolean remove;
	
	public Folder(String path, String relativaPath) {
		this.path = path;
		this.relativePath = relativaPath;
		loadFolder();
	}
	
	public void loadFolder() {

		File file = new File(this.path);
		if (!file.exists()) {
			return;
		}
		String[] filesAndFolders = file.list();
		for (int i = 0; i < filesAndFolders.length; i++) {
			String fileOrFolder = filesAndFolders[i];
			File subFileOrFolder = new File(this.path+File.separator+fileOrFolder);
			if (subFileOrFolder.isDirectory()) {
				Folder subFolder = new Folder(subFileOrFolder.getAbsolutePath(), relativePath+File.separator+fileOrFolder);
				subFolders.add(subFolder);
				totalSize += subFolder.getTotalSize();
				filesNr += subFolder.getFilesNr();
				subFolderNr += 1 + subFolder.getSubFolderNr();
				
			} else {
				MyFile subFile = new MyFile(subFileOrFolder.getAbsolutePath(), relativePath+File.separator+fileOrFolder);
				files.add(subFile);
				totalSize += subFile.getSize();
				filesNr += 1;
			}
		}
	}
	
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public List<MyFile> getFiles() {
		return files;
	}
	public void setFiles(List<MyFile> files) {
		this.files = files;
	}
	public List<Folder> getSubFolders() {
		return subFolders;
	}
	public void setSubFolders(List<Folder> subFolders) {
		this.subFolders = subFolders;
	}

	public int getSubFolderNr() {
		return subFolderNr;
	}

	public void setSubFolderNr(int subFolderNr) {
		this.subFolderNr = subFolderNr;
	}

	public int getFilesNr() {
		return filesNr;
	}

	public void setFilesNr(int filesNr) {
		this.filesNr = filesNr;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}

	public boolean isRemove() {
		return remove;
	}

	public void setRemove(boolean remove) {
		this.remove = remove;
	}

	public String getRelativePath() {
		return relativePath;
	}

	public void setRelativePath(String relativePath) {
		this.relativePath = relativePath;
	}
	
}
